﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_basisset_ChangePasswor : AdminPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckAdmin();
        GetUserPermisions();
    }
    protected void CheckAdmin()
    {
        if (AdminSessionHelper.UserDetails == null)
        {
            JsHelper.TopAlertRedirect("请先登录", "../login.aspx", this.Page);
        }
        else
            hdfuserid.Value = AdminSessionHelper.UserDetails["UserId"].ToString();


    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
        
        int userid=Convert.ToInt32(hdfuserid.Value);
        if (userid > 0)
        {
            string oldpwd = txtoldpwd.Text.Trim();
            string newpwd = txtpwd.Text.Trim();
            if (!CoreTools.ProcessSqlStr(oldpwd, 0))
            {
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
                txtoldpwd.Focus();
            }
            else if (!CoreTools.ProcessSqlStr(newpwd, 0))
            {
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
                txtpwd.Focus();
            }
            else
            {
                int flag = jtDataAccess.ChangePassword(userid, CryptorEngine.GetMd5_32(oldpwd), CryptorEngine.GetMd5_32(newpwd));

                switch (flag)
                {
                    case -1:
                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("修改失败，原密码不正确！"), false);
                        break;
                    case 0:

                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("修改失败！"), false);
                        break;
                    case 1:

                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("修改成功！"), false);
                        break;
                    default:

                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("修改成功！"), false);
                        break;
                }
            }
        }
    }
}